package com.interesting.client.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.interesting.R;
import com.interesting.base.utils.Constant;
import com.interesting.client.application.AppHolder;
import com.interesting.client.bean.VideoInfo;

public class VideoListAdapter extends BaseAdapter {

	private Context context;
	private List<VideoInfo> dataList;
	private LayoutInflater inflater;

	public VideoListAdapter(Context context, List<VideoInfo> dataList) {
		this.context = context;
		this.dataList = dataList;
		this.inflater = LayoutInflater.from(context);
	}

	private class ViewHolder {
		public ImageView photo;
		public TextView title;
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final VideoInfo video = dataList.get(position);
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.video_item_adapter, null);
			ViewHolder vh = new ViewHolder();
			vh.photo = (ImageView) convertView.findViewById(R.id.video_item_photo);
			vh.title = (TextView) convertView.findViewById(R.id.video_item_title);
			convertView.setTag(vh);
		}
		ViewHolder holder = (ViewHolder) convertView.getTag();
		holder.title.setText(video.getVtitle());
		AppHolder.getInsatnce().imageLoader.DisplayImage(Constant.IMGPATH + "/" + video.getImgPath(), holder.photo,
				R.drawable.ic_launcher);
		return convertView;
	}

}
